package com.vne.skyemart.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name = "cartitem",catalog = "skyemart_db")
@AssociationOverrides({
	@AssociationOverride(name = "pk.cart",joinColumns = @JoinColumn(name = "CartID")),
	@AssociationOverride(name = "pk.products",joinColumns = @JoinColumn(name = "ProductID"))	
})
public class CartItem implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5687994842337136891L;
	private CartItemID pk = new CartItemID();
	
	@Column(name = "Quantity",nullable = false)
	private int quantity = 0;
	
	@Column(name = "Amount")
	private double amount = 0;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "CreatedDate",nullable = false)
	private Date createdDate;	
	
	/**
	 * GETTER AND SETTER
	 * 
	 */
	@EmbeddedId
	public CartItemID getPk() {
		return pk;
	}

	public void setPk(CartItemID pk) {
		this.pk = pk;
	}
	@Transient
	public Cart getCart() {
		return getPk().getCart();
	}
	
	public void setCart(Cart cart) {
		getPk().setCart(cart);
	}
	
	@Transient
	public Products getProduct() {
		return getPk().getProducts();
	}
	
	public void setProduct(Products product) {
		getPk().setProducts(product);
	}
	
	public int getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	/**
	 * OTHER
	 */
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;
 
		CartItem that = (CartItem) o;
 
		if (getPk() != null ? !getPk().equals(that.getPk())
				: that.getPk() != null)
			return false;
 
		return true;
	}
 
	public int hashCode() {
		return (getPk() != null ? getPk().hashCode() : 0);
	}
}
